//
//  HWFeedBackHeadTextView.m
//  嗨文
//
//  Created by 响当当 on 2019/1/18.
//  Copyright © 2019年 dongzheng. All rights reserved.
//

#import "HWFeedBackHeadTextView.h"

@interface HWFeedBackHeadTextView()<UITextViewDelegate>
@property (nonatomic, strong)UITextView *textView;
@end

@implementation HWFeedBackHeadTextView

- (UITextView *)textView
{
    if (!_textView)
    {
        _textView = [[UITextView alloc]initWithFrame:CGRectMake(0,0,SCREEN_WIDTH,264*kUIScaleBasePlus)];
        _textView.delegate = self;
        _textView.font = [UIFont systemFontOfSize:18*kUIScaleBasePlus];
        _textView.keyboardType = UIReturnKeyDefault;
        _textView.textAlignment = NSTextAlignmentLeft;
        _textView.textColor = LCHexColor(0x333333);
        _textView.placeHolder = @"感谢您留下宝贵的建议，请输入具体详情。";
    }
    return _textView;
}


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        [self addSubview:self.textView];
    }
    return self;
}

#pragma mark - textView delegate

- (void)textViewDidChange:(UITextView *)textView {
    if (textView.text.length == 0) {
        self.textView.placeHolder = @"感谢您留下宝贵的建议，请输入具体详情。";
    }else{
        self.textView.placeHolder = @"";
    }
}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    if ([text isEqualToString:@"\n"])
    {
        [textView resignFirstResponder];
        return NO;
    }
    
//    if ([text isEqualToString:@""])
//    {
//        self.textView.placeHolder = @"感谢您留下宝贵的建议，请输入具体详情。";
//        return NO;
//    }
    
    
    if (self.getTextBlock)
    {
        self.getTextBlock(text);
    }
    
    return YES;
}
@end
